package com.sca.point.utils;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

import java.util.List;

/**
 * @author liuxianfei
 * @since 2020/11/3 12:53
 */
public class GoodBloomFilter {

    /**
     * 预计要插入多少数据
     */
    private static final int SIZE = 10;

    /**
     * 期望的误判率
     */
    private static final double FPP = 0.01;

    private static BloomFilter<Long> bloomFilter = BloomFilter.create(Funnels.longFunnel(), SIZE, FPP);

    public static void init(List<Long> ids) {
        if (!ids.isEmpty()) {
            ids.forEach(i -> bloomFilter.put(i));
        }
    }

    public static boolean mightContain(Long id) {
        return bloomFilter.mightContain(id);
    }

}
